<?php
include 'functions.php';

$q=$_GET["q"];

$con = connect_db();
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//mysql_select_db("ajfax_demo", $con);

$sql="SELECT cropname FROM CROP WHERE cropname REGEXP '^".$q."'";

$result = mysql_query($sql);

while($row = mysql_fetch_array($result)) {
  $units = getUnitsByCropname($row['cropname']);
  $firephp = FirePHP::getInstance(true);
  $firephp->log($units,'units');
  foreach ($units as $u) {
  	 if ($u != "") {
 	 	print "<a style=\"cursor:default\" onclick=\"addToBasket(this.name)\" name=\"".$row['cropname'] . " - " . $u . "\">" . $row['cropname'] . " - " . $u . "</a><br />";
 	 }
  }
}

//mysql_close($con); // becomes redundant after adding getUnitsByCropname, where it closes db connection there

//some of this code was adapted from http://www.w3schools.com/php/php_ajax_database.asp
?> 